import { createVNode, render } from "vue";
import VideoPlayer from "./VideoPlayer.vue";

function getContainer() {
  const container = document.getElementById("app-vap-container");
  if (container) {
    return container;
  }
  const divContainer = document.createElement("div");
  divContainer.id = "app-vap-container";
  // 添加到body上
  document.body.appendChild(divContainer);
  return divContainer;
}

const renderVap = vNode => {
  const container = getContainer();
  const div = document.createElement("div");
  // 添加到body上
  container.appendChild(div);
  render(vNode, div);
};

// 创建svga动画
export function createVap(options) {
  const { src, jsonSrc, json, loop, onFinished } = options;
  const vNode = createVNode(VideoPlayer, {
    src,
    jsonSrc,
    loop,
    json,
    onFinished
  });
  renderVap(vNode);
}
